package io.renren.service.impl;

import io.renren.dao.JobChangeManagementDao;
import io.renren.entity.JobChangeManagementEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import io.renren.dao.SalaryWelfareManagementDao;
import io.renren.entity.SalaryWelfareManagementEntity;
import io.renren.service.SalaryWelfareManagementService;



@Service("salaryWelfareManagementService")
public class SalaryWelfareManagementServiceImpl implements SalaryWelfareManagementService {
	@Autowired
	private SalaryWelfareManagementDao salaryWelfareManagementDao;

	@Autowired
	private JobChangeManagementDao jobChangeManagementDao;
	
	@Override
	public SalaryWelfareManagementEntity queryObject(Integer id){
		return salaryWelfareManagementDao.queryObject(id);
	}
	
	@Override
	public List<SalaryWelfareManagementEntity> queryList(Map<String, Object> map){
		return salaryWelfareManagementDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return salaryWelfareManagementDao.queryTotal(map);
	}
	
	@Override
	public void save(SalaryWelfareManagementEntity salaryWelfareManagement){
		salaryWelfareManagementDao.save(salaryWelfareManagement);
	}

	@Override
	public void update(SalaryWelfareManagementEntity salary){
		/*SalaryWelfareManagementEntity pojo=salaryWelfareManagementDao.queryObject(salary.getId());
		String postId=salary.getPostId()!=null?salary.getPostId():"";
		String dept=salary.getDepartment()!=null?salary.getDepartment():"";
		String companyId=salary.getCompanyId()!=null?salary.getCompanyId():"";
		String changeType="";
		if(!companyId.equals(pojo.getCompanyId()))
		{
			changeType="公司变动";
		}
		else if(!dept.equals(pojo.getDepartment()))
		{
			changeType="部门变动";

		}else if(!postId.equals(pojo.getPostId()))
		{
			changeType="岗位变动";

		}
		if(!"".equals(changeType)){//不等于空则代表有异动
			saveJobChange(pojo,salary,changeType);

		}*/
		salaryWelfareManagementDao.update(salary);

	}
	
	@Override
	public void delete(Integer id){
		salaryWelfareManagementDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		salaryWelfareManagementDao.deleteBatch(ids);
	}


	public void saveJobChange(SalaryWelfareManagementEntity old,SalaryWelfareManagementEntity newData,String changeType) {
		JobChangeManagementEntity entity=new JobChangeManagementEntity();
		entity.setName(old.getName());
		entity.setIdno(old.getIdno());
		entity.setCompany(old.getCompany());
		entity.setCompanyId(old.getCompanyId());
		entity.setChangeType(changeType);
		entity.setOriginalDepartment(old.getDepartment());
		entity.setOriginalPost(old.getPost());
		entity.setOriginalPostId(old.getPostId());
		entity.setOriginalBaseSalary(old.getBaseSalary());	//原基本工资
        entity.setOriginalAchievementsSalary(old.getAchievementsSalary());//原绩效工资
		entity.setOriginalOvertimePay(old.getOvertimePay());//原加班费
		entity.setPresentUnit(newData.getCompany());//现单位
		entity.setPresentUnitId(newData.getCompanyId());//现单位id
		entity.setPresentDepartment(newData.getDepartment());//现部门
		entity.setPresentPost(newData.getPost());//现岗位
		entity.setPresentPostId(newData.getPostId());//现岗位id
		entity.setPresentBaseSalary(newData.getBaseSalary());		//现基本工资
		entity.setPresentAchievementsSalary(newData.getAchievementsSalary());//现绩效工资
		entity.setPresentOvertimePay(newData.getOvertimePay());//现加班费

		jobChangeManagementDao.save(entity);

	}
}
